/*
Plugin Name: Edit Image Color
Theme URI: http://codecanyon.net/user/eyered
Author: Eyered
Author URI: http://codecanyon.net/user/eyered
Description: A WordPress Plugin
License: GNU General Public License
License URI: license.txt
*/

function createColorEffect(url) {   
    Caman("#normal-select", url, function() {
        this.render(function() {
        });

    });
    Caman("#vintage-select", url, function() {
        this.vintage();
        this.render(function() {
        });
        //$("#target_image").attr("src",this.toBase64()).show().css("top","0").css("left","0");
    });
    Caman("#lomo-select", url, function() {
        this.lomo();
        this.render(function() {
        });
        //$("#target_image").attr("src",this.toBase64()).show().css("top","0").css("left","0");
    });
    Caman("#clarity-select", url, function() {
        this.clarity();
        this.render(function() {
        });
        //$("#target_image").attr("src",this.toBase64()).show().css("top","0").css("left","0");
    });
    Caman("#sincity-select", url, function() {
        this.sinCity();
        this.render(function() {
        });
        //$("#target_image").attr("src",this.toBase64()).show().css("top","0").css("left","0");
    });
    Caman("#sunrise-select", url, function() {
        this.sunrise();
        this.render(function() {
        });
        //$("#target_image").attr("src",this.toBase64()).show().css("top","0").css("left","0");
    });
    Caman("#crossProcess-select", url, function() {
        this.crossProcess();
        this.render(function() {
        });
        //$("#target_image").attr("src",this.toBase64()).show().css("top","0").css("left","0");
    });
    Caman("#orangePeel-select", url, function() {
        this.orangePeel();
        this.render(function() {
        });
        //$("#target_image").attr("src",this.toBase64()).show().css("top","0").css("left","0");
    });
    Caman("#love-select", url, function() {
        this.love();
        this.render(function() {
        });
        //$("#target_image").attr("src",this.toBase64()).show().css("top","0").css("left","0");
    });
    Caman("#grungy-select", url, function() {
        this.grungy();
        this.render(function() {
        });
        //$("#target_image").attr("src",this.toBase64()).show().css("top","0").css("left","0");
    });
    Caman("#jarques-select", url, function() {
        this.jarques();
        this.render(function() {
        });
        //$("#target_image").attr("src",this.toBase64()).show().css("top","0").css("left","0");
    });
    Caman("#pinhole-select", url, function() {
        this.pinhole();
        this.render(function() {
        });
        //$("#target_image").attr("src",this.toBase64()).show().css("top","0").css("left","0");
    });
    Caman("#oldBoot-select", url, function() {
        this.oldBoot();
        this.render(function() {
        });
        //$("#target_image").attr("src",this.toBase64()).show().css("top","0").css("left","0");
    });
    Caman("#glowingSun-select", url, function() {
        this.glowingSun();
        this.render(function() {
        });
        //$("#target_image").attr("src",this.toBase64()).show().css("top","0").css("left","0");
    });
    Caman("#hazyDays-select", url, function() {
        this.hazyDays();
        this.render(function() {
        });
        //$("#target_image").attr("src",this.toBase64()).show().css("top","0").css("left","0");
    });
    Caman("#herMajesty-select", url, function() {
        this.herMajesty();
        this.render(function() {
        });
        //$("#target_image").attr("src",this.toBase64()).show().css("top","0").css("left","0");
    });
    Caman("#nostalgia-select", url, function() {
        this.nostalgia();
        this.render(function() {
        });
        //$("#target_image").attr("src",this.toBase64()).show().css("top","0").css("left","0");
    });
    Caman("#hemingway-select", url, function() {
        this.hemingway();
        this.render(function() {
        });
        //$("#target_image").attr("src",this.toBase64()).show().css("top","0").css("left","0");
    });
    Caman("#concentrate-select", url, function() {
        this.concentrate();
        this.render(function() {
        });
        //$("#target_image").attr("src",this.toBase64()).show().css("top","0").css("left","0");
    });
    $('#color-select').jcarousel({
        itemFallbackDimension: 125
    });
}

function addEffect(id) {
    color_select = id;
    var action = confirm("This action will take a bit time to do!")
    if (action == true)
    {
        $("#target_image_loading").show();
        $("#convertImageContainer").html(convertTagrgetImageObject);
        //alert(image_select);
        if (id == "normal") {
            $("#target_image").attr("src", image_select);
            $("#target_image_loading").hide();
            return;
        }
        Caman("#convert_target_image", image_select, function() {
            if (id == "vintage")
                this.vintage();
            if (id == "lomo")
                this.lomo();
            if (id == "clarity")
                this.clarity();
            if (id == "sincity")
                this.sinCity();
            if (id == "sunrise")
                this.sunrise();
            if (id == "crossProcess")
                this.crossProcess();
            if (id == "orangePeel")
                this.orangePeel();
            if (id == "love")
                this.love();
            if (id == "grungy")
                this.grungy();
            if (id == "jarques")
                this.jarques();
            if (id == "pinhole")
                this.pinhole();
            if (id == "oldBoot")
                this.oldBoot();
            if (id == "glowingSun")
                this.glowingSun();
            if (id == "hazyDays")
                this.hazyDays();
            if (id == "herMajesty")
                this.herMajesty();
            if (id == "nostalgia")
                this.nostalgia();
            if (id == "hemingway")
                this.hemingway();
            if (id == "concentrate")
                this.concentrate();
            this.render(function() {
                $("#target_image").attr("src", this.toBase64())
                $("#target_image_loading").hide();
            });
            //$("#target_image").attr("src",this.toBase64()).show().css("top","0").css("left","0");
        });
    }
}

function openEditContainer(id){
    $("#blur-block").hide().css("left","-10px");
    $(".imgedit-help").hide(300);
    $("#"+id).show(300);
}

function resetImage(){
    $('#RedRange').val(0);
    $('#GreenRange').val(0);
    $('#BlueRange').val(0);
    $('.FilterValue').text(0);
    Pixastic.revert(document.getElementById("convert_target_image"));
    var image = document.getElementById("convert_target_image").getContext('2d').canvas.toDataURL()
    $("#target_image").attr("src", image);
    
}

function adjustColor(){
    var RedValue = $('#RedRange').val()/100;
    var GreenValue = $('#GreenRange').val()/100;
    var BlueValue = $('#BlueRange').val()/100;
    Pixastic.revert(document.getElementById("convert_target_image"));
    Pixastic.process(document.getElementById('convert_target_image'), "coloradjust", {red:RedValue,green:GreenValue,blue:BlueValue});
    var image = document.getElementById("convert_target_image").getContext('2d').canvas.toDataURL()
    $("#target_image").attr("src", image);
}

function blurImage(){
    var left = $('#blur-block').position().left;
    var top = $('#blur-block').position().top;
    var width = $('#blur-block').width();
    var height = $('#blur-block').height();
    Pixastic.process(
                     document.getElementById('convert_target_image'),
                     "blurfast", 
                     {amount:0.5,direction:"topleft", rect:{left:left,top:top,width:width,height:height}
                     }
                 );
    var image = document.getElementById("convert_target_image").getContext('2d').canvas.toDataURL()
    $("#target_image").attr("src", image);
}